<template>
	<view>
		<view class="submitBtn upload" @click="choose">
			Upload lmages
		</view>
		<!-- 
		<uni-file-picker limit="10" :value="imageList" :imageStyles="imageStyles" file-mediatype="image" mode="grid"
			@select="selectImg" @delete="deleteImg">
			<view class="submitBtn upload">
				Upload lmages
			</view>
		</uni-file-picker> -->
	</view>
</template>

<script>
	import {
		domain
	} from '@/utils/request.js'
	export default {
		data() {
			return {
				imageList: [],
				imageUrl: [],
				domain: '',
				imageStyles: {
					width: 100,
					height: 100,
					border: {
						radius: '0'
					}
				},
				list: [],
				showList: []
			};
		},
		props: ['avatar'],
		mounted() {
			this.domain = domain
		},
		methods: {
			choose() {
				uni.chooseImage({
					count: 10, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						console.log(JSON.stringify(res.tempFilePaths));
					}
				});
			},
			selectImg(e) {
				e.tempFiles.forEach(item => {
					this.imageUrl.push(item)
					uni.uploadFile({
						url: this.domain + "api/common/upload",
						header: {
							'token': uni.getStorageSync('token'),
						},
						filePath: item.url,
						name: 'file',
						success: (res) => {
							const data = JSON.parse(res.data)
							// this.imageList = [{
							// 	url: data.data.uri,
							// 	extname: 'png',
							// 	name: 'image.png'
							// }]
							// this.$emit('emitUri', data.data.uri)
							// this.$emit('emitUrl', data.data.url)
						}
					});
				})
			},
			deleteImg(e) {
				this.imageList = []
			},
		}
	}
</script>

<style lang="scss" scoped>
	.choose {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 100px;
		height: 100px;
		margin: 10rpx 0;
		color: #999;
	}

	.chooseVideo {
		border: 1rpx solid #eee;
	}

	/deep/ .uni-file-picker__container {
		position: relative;
	}

	.upload {
		width: 265rpx;
		margin-top: 50rpx 0;
	}

	/deep/ .file-picker__box {
		position: inherit !important;
	}

	/deep/ .uni-file-picker__container {
		margin: 0;
	}

	/deep/ .file-picker__box-content {
		margin: 0;
	}

	/deep/ .uni-file-picker__lists {
		margin-top: 0;
		margin-bottom: 10rpx;
	}
</style>